import 'package:chopper/chopper.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../data/post_api_service.dart';
import '../model/built_post.dart';

class DetailPage extends StatefulWidget {
  DetailPage(this.id);
  final int id;
  @override
  _DetailPageState createState() => _DetailPageState();
}

class _DetailPageState extends State<DetailPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: FutureBuilder<Response<BuiltPost>>(
      future: Provider.of<PostApiService>(context).getPost(widget.id),
      builder: (context, snapshot) {
        if (snapshot.connectionState == ConnectionState.done) {
          return Center(
            child: ListTile(
              title: Text(snapshot.data.body.body),
              subtitle: Text(snapshot.data.body.title),
            ),
          );
        } else {
          return Center(
            child: CircularProgressIndicator(),
          );
        }
      },
    ));
  }
}
